package tq.com.tqteacher.view;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import tq.com.tqcom.util.TQSystemDefine;
import tq.com.tqteacher.R;

public class TQFanweiView extends FrameLayout {
    private TextView allTextview;
    private TextView classTextView;

    private int select = TQSystemDefine.SHOW_TYPE_ALL;


    public TQFanweiView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initLayout();
    }

    public int getSelect(){
        return select;
    }
    public void setSelect(int pSelect){
        select = pSelect;

        setDrawable();
    }

    private void initLayout(){
        LayoutInflater.from(getContext()).inflate(R.layout.view_fanwei_layout, this);

        allTextview = findViewById(R.id.see_all);
        classTextView = findViewById(R.id.see_class);

        allTextview.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(select != TQSystemDefine.SHOW_TYPE_ALL){
                    select = TQSystemDefine.SHOW_TYPE_ALL;
                    setDrawable();
                }
            }
        });
        classTextView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(select != TQSystemDefine.SHOW_MY_CLASS){
                    select = TQSystemDefine.SHOW_MY_CLASS;
                    setDrawable();
                }
            }
        });

        setDrawable();
    }

    private void setDrawable(){
        Drawable sel = getResources().getDrawable(R.drawable.radio_sel, null);
        Drawable normal = getResources().getDrawable(R.drawable.radio_unsel, null);

        if(select == TQSystemDefine.SHOW_TYPE_ALL){
            allTextview.setCompoundDrawablesRelativeWithIntrinsicBounds(sel, null, null, null);
            classTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(normal, null, null, null);
        }else{
            allTextview.setCompoundDrawablesRelativeWithIntrinsicBounds(normal, null, null, null);
            classTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(sel, null, null, null);
        }
    }
}
